<template>
  <div class="wrap" @scroll="loadMore">
    <h2><strong>即将直播</strong></h2>
    <div class="playVideo" v-for="item in broadcast" :key="item.id">
      <div class="author">
        <img :src="'https://ss.lanqb.com/' + item.posters.mobile" alt="" />
      </div>
      <!-- 跳转 -->
      <div class="video_con" @click="to(item.id)">  
        <h4>{{ item.title }}</h4>
        <div class="video_pic">
          <div class="video_pic_item">
            <img :src="'https://ss.lanqb.com/' + item.profile.avatar" />
            <span>{{ item.profile.nickname }}</span>
          </div>
          <div class="video_pic_time">
            <p>时间 : {{ item.begin_at }}</p>
            <p>{{ item.statistic.purchases }}人感兴趣</p>
            <span class="look">立即报名</span>
          </div>
        </div>
      </div>
    </div>

    <!--  往期直播 -->
    <h2><strong>往期直播</strong></h2>
    <div class="playVideo" v-for="item in former" :key="item.id">
      <div class="author">
        <img :src="'https://ss.lanqb.com/' + item.posters.mobile" alt="" />
      </div>
      <div class="video_con"  @click="to(item.id)">
        <h4>{{ item.title }}</h4>
        <div class="video_pic">
          <div class="video_pic_item">
            <img :src="'https://ss.lanqb.com/' + item.user_profile.avatar" />
            <span>{{ item.user_profile.nickname }}</span>
          </div>
          <div class="video_pic_time">
            <p>时间 : {{ item.begin_at }}</p>
            <p>{{ item.statistic.base_interested }}人感兴趣</p>
          </div>
        </div>
      </div>
    </div>
    <div v-show="isShow" style="margin-bottom: 200px">加载中...</div>
  </div>
</template>
<script>
export default {
  name: "DachuActiveOne",
  data() {
    return {
      broadcast: [],
      former: [],
      curPage: 1,
      isShow: true,
      infoId:null,
    };
  },

  methods: {
    // 跳转到详情页
    to(id){
      this.infoId = id
      this.$router.push(`/DachuLiveInfo/${this.infoId}`)
    },
    loadMore(e) {
      const st = e.target.scrollTop;
      const cheight = e.target.clientHeight;
      const theight = e.target.scrollHeight;
      if (st + cheight >= theight) {
        this.curPage++;
        this.isShow = true;
        fetch(
          `https://m.lanqb.com/api/daniu?link=paging&live=3&heat=N&page=${this.curPage}&is_live=1`
        )
          .then((res) => res.json())
          .then((data) => {
            this.former = [...this.former, ...data.course.data];
            console.log(this.former);
            this.isShow = false;
          });
      }
    },
  },
  created() {
    fetch(
      "https://m.lanqb.com/api/daniu?link=paging&live=3&heat=N&page=1&is_live=1"
    )
      .then((res) => res.json())
      .then((data) => {
        this.broadcast = data.live;
        console.log(this.broadcast);
      });

    // 往期直播
    fetch(
      "https://m.lanqb.com/api/daniu?link=paging&live=3&heat=N&page=1&is_live=1"
    )
      .then((res) => res.json())
      .then((data) => {
        this.former = data.course.data;
        console.log(this.former);
      });
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.wrap {
  height: calc(100vh - 220px);
  overflow-y: scroll;
  padding: 10px;
  .playVideo {
    width: 100%;
    display: flex;
    margin-top: 15px;
    box-shadow: 2px 2px 16px rgb(198, 193, 193);
    border-radius: 0px 5px 5px 0px;
    padding: 10px;
    .author {
      img {
        width: 164px;
        height: 130px;
        border-radius: 5px;
        margin-right: 10px;
        padding: 0px;
      }
    }
    .video_con {
      display: flex;
      flex-direction: column;
      color: #333;
      h4 {
        height: 40px;
        font-size: 16px;
      }
      .video_pic {
        .video_pic_item {
          height: 40px;
          line-height: 40px;
          img {
            width: 19px;
            height: 19px;
            border-radius: 50%;
            margin-right: 5px;
          }
          span {
            font-size: 18px;
          }
        }
        .video_pic_time {
          font-size: 12px;
          height: 48px;
          line-height: 24px;
          position: relative;
        }
      }
    }
    .look {
      display: block;
      width: 77px;
      height: 26px;
      line-height: 26px;
      font-size: 11px;
      text-align: center;
      color: #634b19;
      background: #edce8c;
      border-radius: 24px;
      box-shadow: 2px 2px rgba(0, 0, 0, 0.08);
      background-image: linear-gradient(180deg, #f7e9c0, #edce8c);
      position: absolute;
      top: 21px;
      right: 10px;
    }
  }
}

.wrap {
  .playVideo:nth-child(2) {
    display: flex;
    flex-direction: column;
    height: 440px;
    .author > img:nth-child(1) {
      width: 374px;
      height: 279px;
    }
    .video_con > h4:nth-child(1) {
      height: 40px;
      line-height: 40px;
      font-size: 24px;
      font-family: border;
    }
    .video_pic_item:nth-child(1) {
      display: flex;
      margin-top: 5px;
    }
    .video_pic_item > img:nth-child(1) {
      width: 36px;
      height: 36px;
    }
    .video_pic_item > span:nth-child(2) {
      display: block;
      font-size: 22px;
      font-weight: bolder;
      height: 36px;
      line-height: 36px;
      margin-left: 5px;
    }
    .video_pic_time {
      margin-top: 5px;
      height: 46px;
      line-height: 24px;
      color: #9f9f9f;
      position: relative;
      .look {
        display: block;
        width: 110px;
        height: 46px;
        line-height: 46px;
        font-size: 18px;
        text-align: center;
        color: #634b19;
        background: #edce8c;
        border-radius: 24px;
        box-shadow: 2px 2px rgba(0, 0, 0, 0.08);
        background-image: linear-gradient(180deg, #f7e9c0, #edce8c);
        position: absolute;
        top: 0;
        right: 0;
      }
    }
  }
}

.btn {
  text-align: center;
  margin: 20px 0;
  span {
    display: block;
    width: 380px;
    height: 38px;
    line-height: 38px;
    font-size: 20px;
    background: #edce8c;
    color: #634b19;
    cursor: pointer;
    border-radius: 20px;
  }
}
/* 往期直播 */
h2 {
  height: 20px;
  line-height: 20px;
  margin-top: 20px;
}
.former-con {
  div {
    img {
      width: 154px;
      height: 166px;
    }
  }
}
</style>
